import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Author 12629
 * @Description：
 */
public class Game {

    public static final String[] SUITS = {"♥","♠","♦","♣"};

    public List<Card> createCards() {
        List<Card> cardsList = new ArrayList<>();
        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 1; j <= 13; j++) {
                //String suit = SUITS[i];
                //int rank = j;
                Card card = new Card(SUITS[i],j);
                cardsList.add(card);
            }
        }
        return cardsList;
    }

    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for (int i = cardList.size()-1; i > 0; i--) {
            int randIndex = random.nextInt(i);
            swap(cardList,i,randIndex);
        }
    }

    private void swap(List<Card> cardList,int i,int j) {
        /*Card tmp = cardList[i];
        cardList[i] = cardList[j];
        cardList[j] = tmp;*/
        Card tmp = cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,tmp);
    }

    /**
     * 三个人，每个人轮流抓 ,每个人 共5 张牌
     * @param cardList
     */
    public List<List<Card>> play(List<Card> cardList) {

        List<List<Card>> hand = new ArrayList<>();

        List<Card> hand0 = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();

        hand.add(hand0);
        hand.add(hand1);
        hand.add(hand2);

        //每个人总共5张牌
        for (int i = 0; i < 5; i++) {
            //每次 每个人 揭牌1张
            for (int j = 0; j < 3; j++) {
                Card card = cardList.remove(0);
                hand.get(j).add(card);
            }
        }
        return hand;
    }
}
